package com.jie.eclipse.pan.editors.utils;

import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;

/**
 * IStructuredDocument工具类。
 * 提供IStructuredDocument和ITextRegion相关辅助操作。
 *
 * @author zhuxing (mailto:zhu_xing@live.cn)
 */
/*
 * 修改历史
 * $Log$ 
 */
public class StructuredDocumentUtil {
	/**
	 * utility class
	 */
	private StructuredDocumentUtil() {}
	
	/**
	 * 获取特定位置对应的叶子text region
	 * 
	 * @param document   wtp structured document
	 * @param offset     document offset
	 * @return
	 */
	public static ITextRegion getTextRegion(IStructuredDocument document, int offset) {
		IStructuredDocumentRegion structuredRegion = document.getRegionAtCharacterOffset(offset);
		if (structuredRegion == null)
			return null;
		
		return structuredRegion.getRegionAtCharacterOffset(offset);
	}
	
}
